home *** CD-ROM | disk | FTP | other *** search
- Path: xanth!nic.MR.NET!csd4.milw.wisc.edu!leah!itsgw!steinmetz!uunet!allbery
- From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
- Newsgroups: comp.sources.misc
- Subject: v06i026: New version of DVI2TTY, now also for MSDOS
- Message-ID: <47758@uunet.UU.NET>
- Date: 29 Jan 89 21:18:50 GMT
- Sender: allbery@uunet.UU.NET
- Reply-To: mcvax!duteca!marcel@hal.CWRU.Edu (Marcel J.E. Mol)
- Organization: Delft University of Technology, Dep. of Electrotechnical engineering.
- Lines: 2441
- Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
- Organisation: University of Technology, Delft The Netherlands.
- X-Arch-Keywords: c, dvi, portable
-
- Posting-number: Volume 6, Issue 26
- Submitted-by: marcel@duteca.UUCP (Marcel J.E. Mol)
- Archive-name: dvi2tty-2
-
- This is a new version of the DVI2TTY program posted a while ago.
- Many bugs are repaired (including the patch not posted by me).
-
- Now it also runs on MSDOS.
-
- Watch out: the shar file *does* overwrite existing files.
-
- - Marcel
-
- ####################### CUT HERE #######################
- #!/bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #!/bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # README 1695 bytes
- # README.ORG 1051 bytes
- # dvi2tty.1 4291 bytes
- # Makefile 365 bytes
- # commands.h 3506 bytes
- # dvi2tty.h 3778 bytes
- # disdvi.c 14807 bytes
- # dvi2tty.c 23102 bytes
- # dvistuff.c 31593 bytes
- # This archive created: Wed Jan 25 20:20:27 MET 1989
- # By: Marcel J.E. Mol
- export PATH
- echo shar: extracting README
- if test -f 'README'
- then
- echo shar: over-writing existing file "'README'"
- fi
- sed -e 's/^-//' << \_E_O_F_ > README
- - DVI2TTY
- -
- -
- -dvi2tty is intended for previewing dvi-files on text-only
- -devices (terminals and lineprinters).
- -The program is basicly an improved C version of the pascal
- -program written by Svante Lindahl (see README.ORG).
- -I translated it because I could not find a pascal compiler
- -on our machine that could compile it.
- -The program runs under UNIX and MSDOS without problems
- -(you may need some site dependend redefinitions, see below).
- -Undocumented option: the -e option can be used to influence
- -the width of spaces. With a negative value the number of spaces
- -between words becomes less, with a positive value it becomes more.
- -Just play around if you like, -e-11 worked nice with me.
- -
- -
- - DVIDIS
- -
- -dvidis is a simple hack that dumps a dvi file in a more readable form.
- -It is not a spectacular program but use it and improve as you wish.
- -I'd appreciate any enhancements made, bug reports etc. mailed to me.
- -
- -
- - COMPILING THE PROGRAMS
- -
- -Dvidis is rather simple and does not need any modifications.
- -For dvi2tty you may find the following problems:
- -
- - function strchr() can not be found:
- - Your are probably a BSD UNIX or alike.
- - Solution: #define strchr index
- - '/usr/bin/pg' program not found.
- - Solution: change the DEFPAGER macro in dvi2tty.c
- -
- -Thats all, good luck.
- -
- -
- -- Marcel
- ------------------------------------------
- -| Marcel J.E. Mol | They hate you if your're clever
- -| Delft University of Technology | And they despise the fool
- -| The Netherlands | Till you're so fucking crazy
- -| UUCP: marcel@duteca.UUCP | You can't follow the rules.
- ------------------------------------------ - Lennon
- _E_O_F_
- if test 1695 -ne `wc -c < README `; then
- echo shar: "'README'" unpacked with wrong size!
- fi
- echo shar: extracting README.ORG
- if test -f 'README.ORG'
- then
- echo shar: over-writing existing file "'README.ORG'"
- fi
- sed -e 's/^-//' << \_E_O_F_ > README.ORG
- -
- -dvitty is intended for previewing dvi-files on text-only devices
- -(terminals and lineprinters). The output is not very pretty many
- -times, but it still saves quite a lot of work, especially if you
- -have a little ways to walk to a laserprinter, for example.
- -
- -The program was originally written in Hedrick-Pascal, running on
- -TOPS-20, and was later ported to UNIX (BSD, Berkeley-pascal).
- -
- -It is not very smart in all situations, but still serves it pur-
- -pose fairly well.
- -
- -For information on how to use see the man-page.
- -
- -Before compiling and installing inspect the "compile-time cust-
- -omization constants" and change them to suit your site.
- -These constants configure default pager and a little more.
- -
- -Please report complaints, suggestions, bugs and/or fixes to:
- -
- -Svante Lindahl, NADA, KTH Numerical Analysis & Computer Science
- -UUCP: {seismo,mcvax}!enea!ttds!zap Royal Institute of Technology, Sweden
- -ARPA: enea!ttds!zap@seismo.CSS.GOV EAN: zap@cs.kth.sunet
- -
- -The TOPS-20 version of the program can also be obtained from the above
- -address.
- _E_O_F_
- if test 1051 -ne `wc -c < README.ORG `; then
- echo shar: "'README.ORG'" unpacked with wrong size!
- fi
- echo shar: extracting dvi2tty.1
- if test -f 'dvi2tty.1'
- then
- echo shar: over-writing existing file "'dvi2tty.1'"
- fi
- sed -e 's/^-//' << \_E_O_F_ > dvi2tty.1
- -.TH DVI2TTY Local "7 June 1986"
- -.SH NAME
- -dvi2tty \- preview a dvi\-file on an ordinary ascii terminal
- -.SH SYNOPSIS
- -.B dvi2tty
- -[ options ] dvi\-file
- -.SH DESCRIPTION
- -.I dvi2tty
- -converts a TeX DVI\-file to a format that is apprporiate for terminals
- -and lineprinters. The program is intended to be used for
- -preliminary proofreading of TeX-ed documents.
- -By default the output is directed to the terminal,
- -possibly through a pager (depending on how the program was installed),
- -but it can be directed to a file or a pipe.
- -.PP
- -The output leaves much to be desired, but is still
- -usefull if you want to avoid walking to the
- -laserprinter (or whatever) for each iteration of your
- -document.
- -.br
- -Since
- -.I dvi2tty
- -produces output for terminals and lineprinters the
- -representation of documents is naturally quite primitive.
- -Fontchanges are totally ignored, which implies that
- -special symbols, such as mathematical symbols, get mapped into the
- -characters at the corresponding positions in the "standard" fonts.
- -.PP
- -If the width of the output text requires more columns than fits
- -in one line (c.f. the \-w option) it is broken into several lines by
- -.I dvi2tty
- -although they will be printed as one line on regular TeX output
- -devices (e.g.laserprinters). To show that a broken line is really
- -just one logical line an asterisk (``*'') in the last position
- -means that the logical line is continued on the next physical
- -line output by
- -.I dvi2tty.
- -Such a continuation line is started with a a space and an asterisk
- -in the first two columns.
- -.PP
- -Options may be specified in the environment variable DVI2TTY.
- -Any option on the commandline, conflicting with one in the
- -environment, will override the one from the environment.
- -.PP
- -.B Options:
- -.PP
- -.TP
- -.B \-o file
- -Write output to file ``file''.
- -.TP
- -.B \-p list
- -Print the pages chosen by list.
- -Numbers refer to TeX\-page numbers (known as \\count0).
- -An example of format for list is ``1,3:6,8''
- -to choose pages 1, 3 through 6 and 8.
- -Negative numbers can be used exactly as in TeX,
- -e g \-1 comes before \-4 as in ``\-p-1:-4,17''.
- -.TP
- -.B \-P list
- -Like \-p except that page numbers refer to
- -the sequential ordering of the pages in the dvi\-file.
- -Negative numbers don't make a lot of sense here...
- -.TP
- -.B \-w n
- -Specify terminal width
- -.I n.
- -Legal range 16\-132.
- -Default is 80. If your terminal has the
- -ability to display in 132 columns it might
- -be a good idea to use \-w132 and toggle the
- -terminal into this mode as output will
- -probably look somewhat better.
- -.TP
- -.B \-q
- -Don't pipe the output through a pager.
- -This may be the default on some systems
- -(depending on the whims of the SA installing the program).
- -.TP
- -.B \-f
- -Pipe through a pager, $PAGER if defined, or whatever your SA compiled
- -in (often ``more''). This may be the default, but it is still okay
- -to redirect output with ``>'', the pager will not be used if output
- -is not going to a terminal.
- -.TP
- -.B \-F
- -Specify the pager program to be used.
- -This overides the $PAGER and the default pager.
- -.TP
- -.B \-Fprog
- -Use ``prog'' as program to pipe output into. Can be used to choose an
- -alternate pager (e g ``-Fless'').
- -.TP
- -.B \-l
- -Mark pagebreaks with the two-character sequence ``^L''. The default is
- -to mark them with a formfeed character.
- -.TP
- -.B \-u
- -Don't make any attempts to find special Scandinavian characters.
- -If such characters are in the text they will map to ``a'' and ``o''.
- -This is probably the default outside of Scandinavia. (The SA made
- -the decision when the program was installed.)
- -.TP
- -.B \-s
- -Try to find the special Scandinavian characters that on most (?)
- -terminals in Scandinavia are mapped to ``{|}[\\]''.
- -This can be the default, and output from files not containing these
- -special characters will be identical regardless of this option.
- -.SH FILES
- -/usr/ucb/more \ \ \ \
- -probably the default pager.
- -.SH ENVIRONMENT
- -PAGER \ \ \ \ \ \ \ \ \ \ \ \
- -the pager to use.
- -.br
- -DVI2TTY \ \ \ \ \ \ \ \ \ \ \
- -can be set to hold commandline options.
- -.SH "SEE ALSO"
- -TeX, dvi2ps
- -.SH AUTHOR
- -Svante Lindahl, Royal Institute of Technology, Stockholm
- -.br
- -Improved C version: Marcel Mol
- -.br
- -{seismo, mcvax}!enea!ttds!zap
- -.br
- -marcel@duteca.UUCP
- -.SH BUGS
- -Blanks between words get lost quite easy. This is less
- -likely if you are using a wider output than the default 80.
- -.PP
- -Only one file may be specified on the commandline.
- _E_O_F_
- if test 4291 -ne `wc -c < dvi2tty.1 `; then
- echo shar: "'dvi2tty.1'" unpacked with wrong size!
- fi
- echo shar: extracting Makefile
- if test -f 'Makefile'
- then
- echo shar: over-writing existing file "'Makefile'"
- fi
- sed -e 's/^-//' << \_E_O_F_ > Makefile
- -# Makefile for dvi2tty and disdvi 23/01/89 M.J.E. Mol
- -#
- -# For BSD Unix use the following CFLAGS definition
- -# CFLAGS = -Dstrchr=index
- -#
- -# This Makefile does not work for MSDOS. Make your
- -# own one, or compile by hand.
- -#
- -CFLAGS =
- -
- -all: dvi2tty disdvi
- -
- -dvi2tty:dvi2tty.o dvistuff.o
- - cc -o dvi2tty dvi2tty.o dvistuff.o
- -
- -disdvi:disdvi.o
- - cc -o disdvi disdvi.o
- _E_O_F_
- if test 365 -ne `wc -c < Makefile `; then
- echo shar: "'Makefile'" unpacked with wrong size!
- fi
- echo shar: extracting commands.h
- if test -f 'commands.h'
- then
- echo shar: over-writing existing file "'commands.h'"
- fi
- sed -e 's/^-//' << \_E_O_F_ > commands.h
- -/* DVI COMMANDS */
- -#define SETC_000 0 /* typeset character 0 and move right */
- -#define SETC_127 127 /* typeset character 127 and move right */
- -#define SET1 128 /* typeset a character and move right */
- -#define SET2 129 /* ??? */
- -#define SET3 130 /* ??? */
- -#define SET4 131 /* ??? */
- -#define SET_RULE 132 /* typeset a rule and move right */
- -#define PUT1 133 /* typeset a character */
- -#define PUT2 134 /* ??? */
- -#define PUT3 135 /* ??? */
- -#define PUT4 136 /* ??? */
- -#define PUT_RULE 137 /* typeset a rule */
- -#define NOP 138 /* no operation */
- -#define BOP 139 /* beginning of page */
- -#define EOP 140 /* ending of page */
- -#define PUSH 141 /* save the current positions */
- -#define POP 142 /* restore previous positions */
- -#define RIGHT1 143 /* move right */
- -#define RIGHT2 144 /* ??? */
- -#define RIGHT3 145 /* ??? */
- -#define RIGHT4 146 /* ??? */
- -#define W0 147 /* move right by |w| */
- -#define W1 148 /* move right and set |w| */
- -#define W2 149 /* ??? */
- -#define W3 150 /* ??? */
- -#define W4 151 /* ??? */
- -#define X0 152 /* move right by |x| */
- -#define X1 153 /* move right and set |x| */
- -#define X2 154 /* ??? */
- -#define X3 155 /* ??? */
- -#define X4 156 /* ??? */
- -#define DOWN1 157 /* move down */
- -#define DOWN2 158 /* ??? */
- -#define DOWN3 159 /* ??? */
- -#define DOWN4 160 /* ??? */
- -#define Y0 161 /* move down by |y| */
- -#define Y1 162 /* move down and set |y| */
- -#define Y2 163 /* ??? */
- -#define Y3 164 /* ??? */
- -#define Y4 165 /* ??? */
- -#define Z0 166 /* move down by |z| */
- -#define Z1 167 /* move down and set |z| */
- -#define Z2 168 /* ??? */
- -#define Z3 169 /* ??? */
- -#define Z4 170 /* ??? */
- -#define FONT_00 171 /* set current font to 0 */
- -#define FONT_63 234 /* set current font to 0 */
- -#define FNT1 235 /* set current font */
- -#define FNT2 236 /* Same as FNT1, except that arg is 2 bytes */
- -#define FNT3 237 /* Same as FNT1, except that arg is 3 bytes */
- -#define FNT4 238 /* Same as FNT1, except that arg is 4 bytes */
- -#define XXX1 239 /* extension to \.DVI primitives */
- -#define XXX2 240 /* Like XXX1, but 0<=k<65536 */
- -#define XXX3 241 /* Like XXX1, but 0<=k<@t$2^{24}$@> */
- -#define XXX4 242 /* potentially long extension to \.DVI
- - primitives */
- -#define FNT_DEF1 243 /* define the meaning of a font number */
- -#define FNT_DEF2 244 /* ??? */
- -#define FNT_DEF3 245 /* ??? */
- -#define FNT_DEF4 246 /* ??? */
- -#define PRE 247 /* preamble */
- -#define POST 248 /* postamble beginning */
- -#define POST_POST 249 /* postamble ending */
- -#define TRAILER 223 /* trailer bytes in dvi file */
- -
- - /* undefined_commands 250,251,252,253,254,255 */
- _E_O_F_
- if test 3506 -ne `wc -c < commands.h `; then
- echo shar: "'commands.h'" unpacked with wrong size!
- fi
- echo shar: extracting dvi2tty.h
- if test -f 'dvi2tty.h'
- then
- echo shar: over-writing existing file "'dvi2tty.h'"
- fi
- sed -e 's/^-//' << \_E_O_F_ > dvi2tty.h
- -#define Copyright "dvi2tty.c Copyright (C) 1984, 1985, 1986 Svante Lindahl.\n\
- -Copyright (C) 1988 M.J.E. Mol"
- -
- -#include <stdio.h>
- -#if defined(MSDOS)
- -#include <stdlib.h>
- -#include <string.h>
- -#include <malloc.h>
- -#endif
- -
- -#define TRUE 1
- -#define FALSE 0
- -#define nil NULL
- -
- -/*
- - * ERROR CODES , don't start with 0
- - */
- -
- -#define illop 1 /* illegal op-code */
- -#define stkof 2 /* stack over-flow */
- -#define stkuf 3 /* stack under-flow */
- -#define stkrq 4 /* stack requirement */
- -#define lnerq 5 /* line allocation */
- -#define badid 6 /* id is not right */
- -#define bdsgn 7 /* signature is wrong */
- -#define fwsgn 8 /* too few signatures */
- -#define nopre 9 /* no pre-amble where expected */
- -#define nobop 10 /* no bop-command where expected */
- -#define nopp 11 /* no postpost where expected */
- -#define bdpre 12 /* unexpected preamble occured */
- -#define bdbop 13 /* unexpected bop-command occured */
- -#define bdpst 14 /* unexpected post-command occured */
- -#define bdpp 15 /* unexpected postpost */
- -#define nopst 16 /* no post-amble where expected */
- -#define illch 17 /* character code out of range */
- -#define filop 18 /* cannot access file */
- -#define filcr 19 /* cannot creat file */
- -#if !defined(MSDOS)
- -#define pipcr 20 /* cannot creat pipe */
- -#endif
- -
- -/*---------------------------------------------------------------------------*/
- -
- -typedef char bool;
- -
- -typedef struct prlistptr { /* list of pages selected for output */
- - int pag; /* number of pages */
- - bool all; /* pages in interval selected */
- - struct prlistptr *prv; /* previous item in list */
- - struct prlistptr *nxt; /* next item in list */
- -} printlisttype;
- -
- -/*---------------------------------------------------------------------------*/
- -
- -extern bool outputtofile; /* output to file or stdout(dvi2tty.c)*/
- -extern bool pageswitchon; /* user-set pages to print(dvistuff.c)*/
- -extern bool sequenceon; /* not TeX pagenrs (dvistuff.c) */
- -extern bool scascii; /* Scand. nat. chars (dvistuff.c) */
- -extern bool noffd; /* output ^L or formfeed (dvistuff.c) */
- -
- -extern printlisttype *currentpage; /* current page to print (dvi2tty.c) */
- -extern printlisttype *firstpage; /* first page selected (dvi2tty.c) */
- -extern printlisttype *lastpage; /* last page selected (dvi2tty.c) */
- -
- -extern int ttywidth; /* screen width (dvi2tty.c) */
- -extern int espace; /* extra screen width (dvi2tty.c) */
- -extern long foo; /* temporary 'register' (dvi2tty.c) */
- -extern int opcode; /* dvi opcode (dvistuff.c) */
- -
- -extern FILE *DVIfile; /* dvi file (dvi2tty.c) */
- -extern FILE *output; /* output file (dvi2tty.c) */
- -
- -/*---------------------------------------------------------------------------*/
- -
- -/* dvi2tty.c */
- -#if defined(MSDOS)
- -void errorexit(int);
- -#else
- -void errorexit();
- -#endif
- -
- -/* dvistuff.c */
- -#if defined(MSDOS)
- -void dvimain(void);
- -#else
- -void dvimain();
- -#endif
- _E_O_F_
- if test 3778 -ne `wc -c < dvi2tty.h `; then
- echo shar: "'dvi2tty.h'" unpacked with wrong size!
- fi
- echo shar: extracting disdvi.c
- if test -f 'disdvi.c'
- then
- echo shar: over-writing existing file "'disdvi.c'"
- fi
- sed -e 's/^-//' << \_E_O_F_ > disdvi.c
- -/*****************************************************************************/
- -/* */
- -/* disdvi --- disassembles TeX dvi files. */
- -/* */
- -/*****************************************************************************/
- -
- -#include <stdio.h>
- -#include <ctype.h>
- -#include "commands.h"
- -#if defined(MSDOS)
- -#include <stdlib.h>
- -#include <string.h>
- -#include <fcntl.h>
- -#endif
- -
- -#define LASTCHAR 127 /* max dvi character, above are commands */
- -
- -#define get1() num(1)
- -#define get2() num(2)
- -#define get3() num(3)
- -#define get4() num(4)
- -#define sget1() snum(1)
- -#define sget2() snum(2)
- -#define sget3() snum(3)
- -#define sget4() snum(4)
- -
- -
- -FILE * dvifp;
- -char * dvi_name;
- -long pc = 0;
- -
- -char * malloc ();
- -
- -void main ();
- -void bop ();
- -void preamble ();
- -void postamble ();
- -void postpostamble ();
- -void fontdef ();
- -void special ();
- -void printnonprint ();
- -unsigned long num ();
- -long snum ();
- -
- -
- -
- -
- -/*---------------------------------------------------------------------------*/
- -
- -void main(argc, argv)
- -int argc;
- -char **argv;
- -{
- - register int opcode; /* dvi opcode */
- - register int i;
- -
- - if (argc > 2) {
- - fprintf(stderr, "To many arguments\n");
- - fprintf(stderr, "Usage: %s [dvi-file]\n", *argv);
- - exit(1);
- - }
- -
- - if (argc == 2) {
- - if ((i = strlen(argv[1])) == 0) {
- - fprintf(stderr, "Illegal empty filename\n");
- - fprintf(stderr, "Usage: %s [dvi-file]\n", *argv);
- - exit(2);
- - }
- - if ((i >= 5) && (argv[1][i-4] == '.') && (argv[1][i-3] == 'd') &&
- - (argv[1][i-2] = 'v') && (argv[1][i-1] = 'i'))
- - dvi_name = argv[1];
- - else {
- - dvi_name = malloc((i+4) * sizeof(char));
- - strcpy(dvi_name, argv[1]);
- - strcat(dvi_name, ".dvi");
- - }
- - if ((dvifp = fopen(dvi_name, "r")) == NULL) {
- - perror(dvi_name);
- - exit(3);
- - }
- - }
- - else
- - dvifp = stdin;
- -
- -#if defined(MSDOS)
- - setmode(fileno(dvifp), O_BINARY);
- -#endif
- -
- - while ((opcode = (int) get1()) != EOF) { /* process until end of file */
- - printf("%06ld: ", pc - 1);
- - if ((opcode <= LASTCHAR) && isprint(opcode)) {
- - printf("Char: ");
- - while ((opcode <= LASTCHAR) && isprint(opcode)) {
- - putchar(opcode);
- - opcode = (int) get1();
- - }
- - putchar('\n');
- - printf("%06ld: ", pc - 1);
- - }
- -
- - if (opcode <= LASTCHAR)
- - printnonprint(opcode); /* it must be a non-printable */
- - else if ((opcode >= FONT_00) && (opcode <= FONT_63))
- - printf("FONT_%d\n", opcode - FONT_00);
- - else
- - switch (opcode) {
- - case SET1 :
- - case SET2 :
- - case SET3 :
- - case SET4 : printf("SET%d: %ld\n", opcode - SET1 + 1,
- - num(opcode - SET1 + 1));
- - break;
- - case SET_RULE : printf("SET_RULE: %ld, %ld\n", sget4(),
- - sget4());
- - break;
- - case PUT1 :
- - case PUT2 :
- - case PUT3 :
- - case PUT4 : printf("PUT%d: %ld\n", opcode - PUT1 + 1,
- - num(opcode - PUT1 + 1));
- - break;
- - case PUT_RULE : printf("PUT_RULE: %ld, %ld\n", sget4(),
- - sget4());
- - break;
- - case NOP : printf("NOP\n"); break;
- - case BOP : bop(); break;
- - case EOP : printf("EOP\n"); break;
- - case PUSH : printf("PUSH\n"); break;
- - case POP : printf("POP\n"); break;
- - case RIGHT1 :
- - case RIGHT2 :
- - case RIGHT3 :
- - case RIGHT4 : printf("RIGHT%d: %ld\n", opcode - RIGHT1 + 1,
- - snum(opcode - RIGHT1 + 1));
- - break;
- - case W0 : printf("W0\n"); break;
- - case W1 :
- - case W2 :
- - case W3 :
- - case W4 : printf("W%d: %ld\n", opcode - W0,
- - snum(opcode - W0));
- - break;
- - case X0 : printf("X0\n"); break;
- - case X1 :
- - case X2 :
- - case X3 :
- - case X4 : printf("X%d: %ld\n", opcode - X0,
- - snum(opcode - X0));
- - break;
- - case DOWN1 :
- - case DOWN2 :
- - case DOWN3 :
- - case DOWN4 : printf("DOWN%d: %ld\n", opcode - DOWN1 + 1,
- - snum(opcode - DOWN1 + 1));
- - break;
- - case Y0 : printf("Y0\n"); break;
- - case Y1 :
- - case Y2 :
- - case Y3 :
- - case Y4 : printf("Y%d: %ld\n", opcode - Y0,
- - snum(opcode - Y0));
- - break;
- - case Z0 : printf("Z0\n"); break;
- - case Z1 :
- - case Z2 :
- - case Z3 :
- - case Z4 : printf("Z%d: %ld\n", opcode - Z0,
- - snum(opcode - Z0));
- - break;
- - case FNT1 :
- - case FNT2 :
- - case FNT3 :
- - case FNT4 : printf("FNT%d: %ld\n", opcode - FNT1 + 1,
- - num(opcode - FNT1 + 1));
- - break;
- - case XXX1 :
- - case XXX2 :
- - case XXX3 :
- - case XXX4 : special(opcode - XXX1 + 1); break;
- - case FNT_DEF1 :
- - case FNT_DEF2 :
- - case FNT_DEF3 :
- - case FNT_DEF4 : fontdef(opcode - FNT_DEF1 + 1); break;
- - case PRE : preamble(); break;
- - case POST : postamble(); break;
- - case POST_POST: postpostamble(); break;
- - }
- - }
- -
- -} /* main */
- -
- -
- -/*----------------------------------------------------------------------------*/
- -
- -
- -void bop()
- -{
- - int i;
- -
- - printf("BOP page number : %ld\n", sget4());
- - for (i=0; i < 3; i++) {
- - printf("%06ld: ", pc - 1);
- - printf(" %6ld %6ld %6ld\n", sget4(), sget4(), sget4());
- - }
- - printf("%06ld: ", pc - 1);
- - printf(" prev page offset : %06ld\n", sget4());
- -
- -} /* bop */
- -
- -
- -/*---------------------------------------------------------------------------*/
- -
- -void postamble()
- -{
- -
- - printf("POST last page offset : %06ld\n", sget4());
- - printf("%06ld: ", pc - 1);
- - printf(" numerator : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" denominator : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" magnification : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" max page height : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" max page width : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" stack size needed: %d\n", (int) get2());
- - printf("%06ld: ", pc - 1);
- - printf(" number of pages : %d\n", (int) get2());
- -
- -} /* postamble */
- -
- -void preamble()
- -{
- - register int i;
- -
- - printf("PRE version : %d\n", (int) get1());
- - printf("%06ld: ", pc - 1);
- - printf(" numerator : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" denominator : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" magnification : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - i = (int) get1();
- - printf(" job name (%03d) :", i);
- - while (i-- > 0)
- - putchar((int) get1());
- - putchar('\n');
- -
- -} /* preamble */
- -
- -
- -void postpostamble()
- -{
- - register int i;
- -
- - printf("POSTPOST postamble offset : %06ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" version : %d\n", (int) get1());
- - while ((i = (int) get1()) == TRAILER) {
- - printf("%06d: ", pc - 1);
- - printf("TRAILER\n");
- - }
- - while (i != EOF) {
- - printf("%06ld: ", pc - 1);
- - printf("BAD DVI FILE END: 0x%02X\n", i);
- - i = (int) get1();
- - }
- -
- -} /* postpostamble */
- -
- -
- -
- -void special(x)
- -register int x;
- -{
- - register long len;
- - register long i;
- -
- - len = num(x);
- - printf("XXX%d: %ld bytes\n", x, len);
- - printf("%06ld: ", pc - 1);
- - for (i = 0; i < len; i++)
- - putchar((int) get1());
- - putchar('\n');
- -
- -} /* special */
- -
- -
- -
- -void fontdef(x)
- -register int x;
- -{
- - register int i;
- -
- - printf("FNT_DEF%d: %ld\n", x, num(x));
- - printf("%06ld: ", pc - 1);
- - printf(" checksum : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" scale : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" design : %ld\n", get4());
- - printf("%06ld: ", pc - 1);
- - printf(" name : ");
- - for (i = (int) get1() + (int) get1(); i > 0; i--)
- - putchar((int) get1());
- - putchar('\n');
- -
- -} /* fontdef */
- -
- -
- -
- -void printnonprint(ch)
- -register int ch;
- -{
- -
- - printf("Char: ");
- - switch (ch) {
- - case 11 : printf("ff /* ligature (non-printing) */"); break;
- - case 12 : printf("fi /* ligature (non-printing) */"); break;
- - case 13 : printf("fl /* ligature (non-printing) */"); break;
- - case 14 : printf("ffi /* ligature (non-printing) */"); break;
- - case 15 : printf("ffl /* ligature (non-printing) */"); break;
- - case 16 : printf("i /* (non-printing) */"); break;
- - case 17 : printf("j /* (non-printing) */"); break;
- - case 25 : printf("ss /* german (non-printing) */"); break;
- - case 26 : printf("ae /* scadinavian (non-printing) */");
- - break;
- - case 27 : printf("oe /* scadinavian (non-printing) */");
- - break;
- - case 28 : printf("o /* scadinavian (non-printing) */");
- - break;
- - case 29 : printf("AE /* scadinavian (non-printing) */");
- - break;
- - case 30 : printf("OE /* scadinavian (non-printing) */");
- - break;
- - case 31 : printf("O /* scadinavian (non-printing) */");
- - break;
- - default : printf("0x%2X", ch); break;
- - }
- - putchar('\n');
- -
- -}
- -
- -
- -
- -unsigned long num(size)
- -register int size;
- -{
- - register int i;
- - register long x = 0;
- -
- - pc += size;
- - for (i = 0; i < size; i++)
- - x = (x << 8) + (unsigned) getc(dvifp);
- - return x;
- -
- -} /* num */
- -
- -
- -
- -long snum(size)
- -register int size;
- -{
- - register int i;
- - register long x = 0;
- -
- - pc += size;
- - x = getc(dvifp);
- - if (x & 0x80)
- - x -= 0x100;
- - for (i = 1; i < size; i++)
- - x = (x << 8) + (unsigned) getc(dvifp);
- - return x;
- -
- -} /* snum */
- -
- -
- -
- -/*
- -
- -
- -================================================================================
- -== DVI file format ==
- -================================================================================
- -no_ops >= 0 bytes (NOP, nops before the preamble)
- -preamble_marker 1 ubyte (PRE)
- -version_id 1 ubyte (should be version 2)
- -numerator 4 ubytes (numerater must equal the one in postamble)
- -denominator 4 ubytes (denominator must equal the one in postamble)
- -magnification 4 ubytes (magnification must equal the one in postamble)
- -id_len 1 ubyte (lenght of identification string)
- -id_string id_len ubytes (identification string)
- -
- -no_ops >= 0 bytes (NOP, nops before a page)
- -begin_of_page 1 ubyte (BOP)
- -page_nr 4 sbytes (page number)
- -do_be_do 36 bytes (filler ????)
- -prev_page_offset 4 sbytes (offset in file where previous page starts, -1 for none)
- -... PAGE DATA ...
- -end_of_page 1 ubyte (EOP)
- -
- -no_ops ??? >= 0 bytes (NOPS, I think they are allowed here...)
- -postamble_marker 1 ubyte (POST)
- -last_page_offset 4 sbytes (offset in file where last page starts)
- -numerator 4 ubytes (numerater must equal the one in preamble)
- -denominator 4 ubytes (denominator must equal the one in preamble)
- -magnification 4 ubytes (magnification must equal the one in preamble)
- -max_page_height 4 ubytes (maximum page height)
- -max_page_width 4 ubytes (maximum page width)
- -max_stack 2 ubytes (maximum stack depth needed)
- -total_pages 2 ubytes (number of pages in file)
- -... FONT DEFINITIONS ...
- -
- -postamble_offset 4 sbytes (offset in file where postamble starts)
- -version_id 1 ubyte (should be version 2)
- -trailer >= 4 ubytes (TRAILER)
- -<EOF>
- -
- -
- -FONT DEFINITIONS:
- - do {
- - switch (c = getc(dvi_fp) {
- - case FNTDEF1 :
- - case FNTDEF2 :
- - case FNTDEF3 :
- - case FNTDEF4 : define_font(c);
- - case POSTPOST : break;
- - default : error;
- - }
- - } while (c != POSTPOST);
- -
- -===== A font def looks like:
- -
- -1,2,3 or 4 ubytes TeXfontnumber for FNTDEF1 .. FNTDEF4
- -4 ubytes checksum
- -4 ubytes scale
- -4 ubytes design size
- -1 byte deflen1
- -1 byte deflen2
- -deflen1 + deflen2 bytes fontname.
- -
- -===== A special looks like:
- -
- -1,2,3 or 4 ubytes telling length of special command for XXX1 .. XXX4
- -all bytes in the special command are used as defined in the dvi driver.
- -
- -
- -*/
- _E_O_F_
- if test 14807 -ne `wc -c < disdvi.c `; then
- echo shar: "'disdvi.c'" unpacked with wrong size!
- fi
- echo shar: extracting dvi2tty.c
- if test -f 'dvi2tty.c'
- then
- echo shar: over-writing existing file "'dvi2tty.c'"
- fi
- sed -e 's/^-//' << \_E_O_F_ > dvi2tty.c
- -/******************************************************************************
- - * Marcel Mol: 1989-01-19 (UUCP: duteca!marcel)
- - * Changed in option handling, no change
- - * in user interface (only the undocumented
- - * feature -e).
- - * Version 3.1.
- - * Marcel Mol: 1989-01-11 (UUCP: duteca!marcel)
- - * Changed some longs to ints.
- - * It now also runs on MSDOS Microsoft C 5.1
- - * New version: 3.0
- - * Marcel Mol: 1989-01-03 (UUCP: duteca!marcel)
- - * Fixed a bugs concerning pager programs
- - * and scanning environment variable DVI2TTY.
- - * Marcel Mol: 1988-10-25 (UUCP: duteca!marcel)
- - * dvi2tty.c dvi2tty.h dvistuff.c commands.h
- - * Converted program to C.
- - * improved spacing between words/characters.
- - * bogart:/usr/alla/zap/dvitty/dvitty.p 1986-08-15 20:24:31,
- - * Version to be sent to mod.sources ready.
- - * New option since last version:
- - * -Fprog Pipe output to prog. Can be used to get a different
- - * pager than the default.
- - * bogart:/usr/alla/zap/dvitty/dvitty.p 1986-01-13 21:49:31,
- - * Environment variable DVITTY is read and options can be set from it.
- - * These are the currently implemented options:
- - * -ofile Write output to file, else write to stdout,
- - * possibly piped through a pager if stdout is a tty.
- - * -plist Print pages whos TeX-page-number are in list.
- - * List is on the form 1,3:6,8 to choose pages
- - * 1,3-6 and 8. TeX-nrs can be negative: -p-1:-4,4
- - * -Plist Print pages whos sequential number are in list.
- - * -wn Print the lines with width n characters, default is
- - * 80. Wider lines gives better results.
- - * -q Don't try to pipe to a pager.
- - * -f Try to pipe to a pager if output is a tty.
- - * -Fname Specify a pager program.
- - * Default of -q and -f is a compile time option, a constant.
- - * -l Write '^L' instead of formfeed between pages.
- - * -u Don't try to find Scandinavian characters (they will
- - * print as a:s and o:s if this option is choosen).
- - * -s Scandinavian characters printed as }{|][\.
- - * Default of -s and -u is a compile time option, a constant.
- - * bogart:/usr/alla/zap/dvitty/dvitty.p 1986-01-10 18:51:03,
- - * Argument parsing, and random access functions (external, in C)
- - * and other OS-dependent stuff (in C). Removed private 'pager' &
- - * tries to pipe through PAGER (environment var) or, if PAGER not
- - * defined, /usr/ucb/more. Some changes for efficency.
- - * bogart:/usr/alla/svante/dvitty/dvitty.p 1985-07-15 20:51:00,
- - * The code for processing dvi-files running on UNIX (UCB-Pascal)
- - * but no argument parsing.
- - * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.140, 30-Mar-85 05:43:56,
- - * Edit: Svante Lindahl
- - * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.136, 15-Jan-85 13:52:59,
- - * Edit: Svante Lindahl, final Twenex version !!!??
- - * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.121, 14-Jan-85 03:10:22,
- - * Edit: Svante Lindahl, cleaned up and fixed a lot of little things
- - * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.25, 15-Dec-84 05:29:56,
- - * Edit: Svante Lindahl, COMND-interface, including command line scanning
- - * VERA::SS:<SVANTE-LINDAHL.WORK>DVITTY.PAS.23, 10-Dec-84 21:24:41,
- - * Edit: Svante Lindahl, added command line scanning with Rscan-JSYS
- - * VERA::<SVANTE-LINDAHL.DVITTY>DVITTY.PAS.48, 8-Oct-84 13:26:30,
- - * Edit: Svante Lindahl, fixed switch-parsing, destroyed by earlier patches
- - * VERA::<SVANTE-LINDAHL.DVITTY>DVITTY.PAS.45, 29-Sep-84 18:29:53,
- - * Edit: Svante Lindahl
- - *
- - * dvitty - get an ascii representation of a dvi-file, suitable for ttys
- - *
- - * This program, and any documentation for it, is copyrighted by Svante
- - * Lindahl. It may be copied for non-commercial use only, provided that
- - * any and all copyright notices are preserved.
- - *
- - * Please report any bugs and/or fixes to:
- - *
- - * UUCP: {seismo,mcvax,cernvax,diku,ukc,unido}!enea!ttds!zap
- - * ARPA: enea!ttds!zap@seismo.CSS.GOV
- - * or Svante_Lindahl_NADA%QZCOM.MAILNET@MIT-MULTICS.ARPA
- - * EAN: zap@cs.kth.sunet
- - */
- -
- -
- -#include "dvi2tty.h"
- -
- - /*-----------------------------------------------------------------------*/
- - /* The following constants may be toggled before compilation to */
- - /* customize the default behaviour of the program for your site. */
- - /* Whichever their settings are, the defaults can be overridden at */
- - /* runtime. */
- - /*-----------------------------------------------------------------------*/
- -
- -#define DEFSCAND FALSE /* default is Scandinavian, toggle this if you */
- - /* don't have terminals with Scand. nat. chars */
- -#define WANTPAGER TRUE /* default: try to pipe through a pager (like */
- - /* more) if stdout is tty and no -o switch */
- -#define DEFPAGER "/usr/bin/pg" /* CHANGE TO YOUR LOCAL PAGER */
- -
- - /*------------------ end of customization constants ---------------------*/
- -
- -#define MAXLEN 100 /* size of char-arrays for strings */
- -#if defined(MSDOS)
- -#define OPTSET "wepPousl" /* legal options */
- -#define OPTWARG "wepPo" /* options with argument */
- -#else
- -#define OPTSET "wepPousqlfF"/* legal options */
- -#define OPTWARG "wepPoF" /* options with argument */
- -#endif
- -
- -/*
- - * USAGE CODES
- - */
- -
- -#define wrnge 1 /* width switch arg out of range */
- -#define ign 2 /* ignore cause, print 'Usage:..' */
- -#define nan 3 /* not a number where one expected */
- -#define gae 4 /* garbage at end */
- -#define bdlst 5 /* bad page-numberlist */
- -#define onef 6 /* only one dvifile allowed */
- -#define bdopt 7 /* bad option */
- -#define onepp 8 /* only one page list allowed */
- -#define noarg 9 /* argument expected */
- -
- -char *dvi2tty = "(#)@ dvi2tty.c 3.1 23/01/89 M.J.E. Mol (c) 1989"
- -
- -/*---------------------------------------------------------------------------*/
- -
- -printlisttype * currentpage; /* current page to print */
- -printlisttype * firstpage; /* first page selected */
- -printlisttype * lastpage; /* last page selected */
- -
- -FILE * DVIfile;
- -FILE * output;
- -bool outputtofile; /* tells if output goes to file or stdout */
- -int ttywidth; /* max nr of chars per printed line */
- -int espace; /* to fake calcs with ttywidth */
- -
- -long foo; /* utility variable, "register" */
- -#if !defined(MSDOS)
- -bool pager; /* tells if output is piped to a pager */
- -char * path; /* name of the pager to run */
- -#endif
- -char * progname; /* our name */
- -int Argc;
- -char ** Argv;
- -char DVIfilename[MAXLEN];
- -char * OUTfilename;
- -char optch; /* for option handling */
- -
- -/*---------------------------------------------------------------------------*/
- -
- -#if defined(MSDOS)
- -void main (int, char **);
- -void setoption (char *);
- -void getargs (void);
- -void getpages (int, char *);
- -void plcnxt (int);
- -void getname (char *);
- -int getinteger(int *, int *, char *);
- -void usage (int);
- -#else
- -char * getenv ();
- -FILE * popen ();
- -
- -void main ();
- -void setoption ();
- -void getargs ();
- -void getpages ();
- -void plcnxt ();
- -void getname ();
- -int getinteger();
- -void usage ();
- -#endif
- -
- -
- -/****************************************************************************/
- -/* */
- -/* M A I N */
- -/* */
- -/****************************************************************************/
- -
- -void main(argc, argv)
- -int argc;
- -char ** argv;
- -{
- -
- - progname = *argv;
- - Argc = argc;
- - Argv = argv;
- -
- - getargs(); /* read command line arguments */
- -#if defined(MSDOS)
- - if ((DVIfile = fopen(DVIfilename, "rb")) == NULL)
- -#else
- - if ((DVIfile = fopen(DVIfilename, "r")) == NULL)
- -#endif
- - errorexit(filop); /* can't open dvifile */
- -
- - if (outputtofile) { /* open the outfile, if needed */
- - if ((output = fopen(OUTfilename, "w")) == NULL)
- - errorexit(filcr);
- -#if !defined(MSDOS)
- - pager = FALSE;
- -#endif
- - }
- - else {
- - output = stdout;
- -#if !defined(MSDOS)
- - if (isatty(fileno(output)) && pager) { /* try to pipe to a pager */
- - if ((output = popen(path, "w")) == NULL) /* get pipe to pager */
- - errorexit(pipcr); /* make output to output */
- - }
- - else
- - pager = FALSE;
- -#endif
- - }
- -
- - dvimain();
- -
- -#if !defined(MSDOS)
- - if (pager)
- - pclose(output); /* close pipe to pager */
- -#endif
- -
- - exit(0);
- -
- -} /* main */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void setoption(optarg)
- -char *optarg;
- -{
- - int j = 0;
- - int ret;
- -
- - while (strchr(OPTSET, optch) != NULL) {
- - switch (optch) {
- -#if !defined(MSDOS)
- - case 'q' : pager = FALSE; break;
- - case 'f' : pager = TRUE; break;
- -#endif
- - case 'l' : noffd = TRUE; break;
- - case 's' : scascii = TRUE; break;
- - case 'u' : scascii = FALSE; break;
- - case 'P' :
- - sequenceon = TRUE; /* fall through */
- - case 'p' :
- - if (pageswitchon)
- - usage(onepp);
- - getpages(j, optarg);
- - break;
- - case 'w' :
- - if (getinteger(&ttywidth, &j, optarg))
- - usage(nan);
- - if (optarg[j] != '\0')
- - usage(gae);
- - if ((ttywidth < 16) || (ttywidth > 132))
- - usage(wrnge);
- - break;
- - case 'e' :
- - if (getinteger(&espace, &j, optarg))
- - usage(nan);
- - if (optarg[j] != '\0')
- - usage(gae);
- - break;
- - case 'o' :
- - OUTfilename = optarg;
- - outputtofile = TRUE;
- - j = strlen(optarg);
- - break;
- -#if !defined(MSDOS)
- - case 'F' :
- - pager = TRUE;
- - path = optarg;
- - j = strlen(optarg);
- - break;
- -#endif
- - default :
- - usage(bdopt);
- - }
- - if ((optch = optarg[j]) == '\0')
- - break;
- - j++;
- - if ((strchr(OPTWARG, optch) != NULL) && (optarg[j]='\0')) {
- - if (--Argc <= 0)
- - usage(noarg);
- - optarg = *++Argv;
- - j = 0;
- - }
- - }
- -} /* setoption */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void getargs()
- -{
- - char *str, *envp;
- - bool DVIfound; /* if a dvi filename found */
- -
- - if (Argc <= 1)
- - usage(ign);
- -
- - pageswitchon = FALSE; /* show all pages */
- - sequenceon = FALSE; /* selected pages are TeX-numbered */
- - outputtofile = FALSE; /* write to stdout */
- -#if !defined(MSDOS)
- - pager = WANTPAGER; /* want paging, compile time option */
- -#endif
- - noffd = FALSE; /* print formfeed between pages */
- - scascii = DEFSCAND; /* scandinavian, compile time option */
- - ttywidth = 80; /* default terminal width */
- - espace = 0; /* to fake ttywith calcs */
- - DVIfound = FALSE;
- -
- -#if !defined(MSDOS)
- - if ((path = getenv("PAGER")) == NULL) /* find default pathname of page */
- - path = DEFPAGER; /* program in case paging is wanted */
- -#endif
- -
- - if ((envp = getenv("DVI2TTY")) != NULL) {
- - while (*envp == ' ')
- - envp++;
- - while (*envp) { /* environment var args */
- - if (strchr(OPTSET, optch = *envp++) != NULL) {
- - /*
- - * we always pass one option, and arrange for optarg ourselfves,
- - * so setoption does not mesh up Argv
- - */
- - if (strchr(OPTWARG, optch) != NULL) {
- - while (*envp == ' ')
- - envp++;
- - if (*envp == '\0')
- - usage(noarg);
- - str = envp; /* str points to optarg */
- - while ((*envp != ' ') && (*envp != '\0'))
- - *envp++; /* set envp just after optarg */
- - if (*envp != '\0')
- - *envp++ = '\0'; /* end optarg string */
- - }
- - else
- - str = "";
- - setoption(str);
- - }
- - else
- - usage(bdopt);
- - while (*envp == ' ')
- - envp++;
- - }
- - }
- -
- - while (--Argc > 0) { /* command line args */
- - str = *++Argv;
- - if (*str != '-') { /* argument is not an option */
- - if (DVIfound) /* only one dvi file allowed */
- - usage(onef);
- - getname(str);
- - DVIfound = TRUE;
- - }
- - else if (strchr(OPTSET, optch = *++str) != NULL) {
- - str++; /* point to rest of argument if any */
- - if ((strchr(OPTWARG, optch) != NULL) && (*str == '\0')) {
- - if (--Argc <= 0)
- - usage(noarg);
- - str = *++Argv;
- - }
- - setoption(str);
- - }
- - else
- - usage(bdopt);
- - }
- -
- - if (!DVIfound)
- - usage(ign);
- -
- -} /* getargs */
- -
- -/*---------------------------------------------------------------------------*/
- -
- -void getpages(j, str)
- -int j;
- -char *str;
- -{
- - int i, c;
- - int num;
- -
- - pageswitchon = TRUE;
- - firstpage = (printlisttype *) malloc(sizeof(printlisttype));
- - firstpage->all = FALSE;
- - firstpage->nxt = nil;
- - firstpage->pag = 0;
- - lastpage = firstpage;
- - currentpage = firstpage;
- - if (getinteger(&num, &j, str))
- - usage(nan);
- - plcnxt((int) num);
- - while (str[j]) {
- - c = str[j];
- - if (c == ',' || c == ':') {
- - j++;
- - if (getinteger(&num, &j, str))
- - usage(nan);
- - }
- - else
- - break;
- - if (c == ',')
- - plcnxt(num);
- - else {
- - if (currentpage->pag < 0) {
- - if (num > 0) {
- - currentpage->all = TRUE;
- - plcnxt(num);
- - }
- - else if (num < currentpage->pag)
- - for (i = currentpage->pag - 1; i >= num; i--)
- - plcnxt(i);
- - else
- - usage(bdlst);
- - }
- - else {
- - if (num < currentpage->pag)
- - usage(bdlst);
- - for (i = currentpage->pag + 1; i <= num; i++)
- - plcnxt(i);
- - }
- - }
- - }
- - if ((str[j] != ' ') && (str[j] != NULL)) {
- - usage(gae);
- - }
- - currentpage = firstpage;
- -
- -} /* getpages */
- -
- -
- -void plcnxt(pagnr) /* place page-nr next in list */
- -int pagnr;
- -{
- - currentpage = lastpage;
- - currentpage->pag = pagnr;
- - lastpage = (printlisttype *) malloc(sizeof(printlisttype));
- - lastpage->all = FALSE;
- - lastpage->nxt = nil;
- - lastpage->pag = 0;
- - currentpage->nxt = lastpage;
- -
- -} /* plcnxt */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void getname(str)
- -char *str;
- -{
- - int i;
- -
- - i = strlen(str);
- - if (i == 0)
- - usage(ign);
- - strcpy(DVIfilename, str);
- - if (!((i >= 5) && (str[i-1] == 'i') && (str[i-2] == 'v') &&
- - (str[i-3] = 'd') && (str[i-4] = '.'))) {
- - strcat(DVIfilename, ".dvi");
- - }
- -
- -} /* getname */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -int getinteger(dest, j, str)
- -int *dest;
- -int *j;
- -char *str;
- -{
- - int cum;
- - int sgn;
- - char ch;
- -
- - ch = str[*j];
- - if (ch == '-') {
- - sgn = -1;
- - ch = str[++(*j)];
- - }
- - else
- - sgn = 1;
- - if ((ch >= '0') && (ch <= '9')) {
- - cum = 0;
- - while ((ch >= '0') && (ch <= '9')) {
- - cum = cum*10 + ch - '0';
- - ch = str[++(*j)];
- - }
- - *dest = sgn * cum;
- - return 0; /* return ok */
- - }
- - return 1; /* return error */
- -
- -} /* getinteger */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void errorexit(errorcode)
- -int errorcode;
- -{
- -
- - fprintf(stderr, "%s: ", progname);
- - switch (errorcode) {
- - case illop : fprintf(stderr, "Illegal op-code found: %d\n", opcode);
- - break;
- - case stkof : fprintf(stderr, "Stack overflow\n");
- - break;
- - case stkuf : fprintf(stderr, "Stack underflow\n");
- - break;
- - case stkrq : fprintf(stderr, "Cannot create dvi stack\n");
- - break;
- - case lnerq : fprintf(stderr, "Cannot allocate memory\n");
- - break;
- - case badid : fprintf(stderr, "Id-byte is not correct: %d\n ", opcode);
- - break;
- - case bdsgn : fprintf(stderr, "Bad signature: %d (not 223)\n",
- - (int) foo);
- - break;
- - case fwsgn : fprintf(stderr, "%d signature bytes (min. 4)\n",
- - (int) foo);
- - break;
- - case nopre : fprintf(stderr, "Missing preamble\n");
- - break;
- - case nobop : fprintf(stderr, "Missing beginning-of-page command\n");
- - break;
- - case nopp : fprintf(stderr, "Missing post-post command\n");
- - break;
- - case bdpre : fprintf(stderr, "Preamble occured inside a page\n");
- - break;
- - case bdbop : fprintf(stderr, "BOP-command occured inside a page\n");
- - break;
- - case bdpst : fprintf(stderr, "Postamble occured before end-of-page\n");
- - break;
- - case bdpp : fprintf(stderr, "Postpost occured before post-command\n");
- - break;
- - case nopst : fprintf(stderr, "Missing postamble\n");
- - break;
- - case illch : fprintf(stderr, "Character code out of range, 0..127\n");
- - break;
- - case filop : fprintf(stderr, "Cannot open dvifile\n");
- - break;
- - case filcr : fprintf(stderr, "Cannot create outfile\n");
- - break;
- -#if !defined(MSDOS)
- - case pipcr : fprintf(stderr, "Cannot create pipe to pager\n");
- - break;
- -#endif
- - default : fprintf(stderr, "Unkown error code\n");
- - break;
- - };
- - if (outputtofile)
- - unlink(OUTfilename);
- - exit(errorcode);
- -
- -} /* errorexit */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void usage(uerr)
- -int uerr;
- -{
- -
- - if (uerr != ign) {
- - fprintf(stderr,"%s: ", progname);
- - switch (uerr) {
- - case ign : fprintf(stderr, "%s", Copyright);
- - break;
- - case wrnge : fprintf(stderr, "width arg out of range:16-132");
- - break;
- - case nan : fprintf(stderr, "numeric argument expected for option %c",
- - optch);
- - break;
- - case gae : fprintf(stderr, "garbage in argument for option %c",
- - optch);
- - break;
- - case bdlst : fprintf(stderr, "mal-formed list of pagenumbers");
- - break;
- - case onef : fprintf(stderr, "only one infile argument allowed");
- - break;
- - case noarg : fprintf(stderr, "option argument expected for option %c",
- - optch);
- - break;
- - case bdopt : fprintf(stderr, "bad option %c", optch);
- - break;
- - case onepp : fprintf(stderr, "only one pagelist allowed");
- - break;
- - default : fprintf(stderr, "unknown usage error");
- - break;
- - }
- - fprintf(stderr, "\n");
- - }
- - fprintf(stderr, "Usage: %s [ options ] dvifile[.dvi]\n", progname);
- - fprintf(stderr, "Options are:\n");
- - fprintf(stderr,
- - " -ofile Write output to file, else write to stdout.\n");
- - fprintf(stderr,
- - " -plist Print pages whos TeX-page-number are in list.\n");
- - fprintf(stderr,
- - " -Plist Print pages whos sequential number are in list.\n");
- - fprintf(stderr,
- - " -wn Print the lines with width n characters, default 80.\n");
- -#if !defined(MSDOS)
- - fprintf(stderr, " -f Try to pipe to a pager if output is a tty");
- - if (WANTPAGER)
- - fprintf(stderr, " (default).\n");
- - else
- - fprintf(stderr, ".\n");
- - fprintf(stderr, " -q Don't try to pipe to a pager");
- - if (WANTPAGER)
- - fprintf(stderr, ".\n");
- - else
- - fprintf(stderr, " (default).\n");
- - fprintf(stderr, " -Fprog Pipe output to pager prog.\n");
- -#endif
- - fprintf(stderr,
- - " -l Write ''^L'' instead of formfeed between pages.\n");
- - fprintf(stderr,
- - " -u National Swedish characters printed as aaoAAO");
- - if (DEFSCAND)
- - fprintf(stderr, ".\n");
- - else
- - fprintf(stderr, " (default).\n");
- - fprintf(stderr,
- - " -s National Swedish characters printed as }{|][\\");
- - if (DEFSCAND)
- - fprintf(stderr, " (default).\n");
- - else
- - fprintf(stderr, ".\n");
- - exit(uerr);
- -
- -} /* usage */
- -
- _E_O_F_
- if test 23102 -ne `wc -c < dvi2tty.c `; then
- echo shar: "'dvi2tty.c'" unpacked with wrong size!
- fi
- echo shar: extracting dvistuff.c
- if test -f 'dvistuff.c'
- then
- echo shar: over-writing existing file "'dvistuff.c'"
- fi
- sed -e 's/^-//' << \_E_O_F_ > dvistuff.c
- -
- -
- -#include "dvi2tty.h"
- -#include <sys/types.h>
- -#include <sys/stat.h>
- -#if defined(MSDOS)
- -#include <math.h>
- -#endif
- -#include "commands.h"
- -
- -#define VERSIONID 2 /* dvi version number that pgm handles */
- -#define VERTICALEPSILON 450000L /* crlf when increasing v more than this */
- -
- -#define rightmargin 152 /* nr of columns allowed to the right of h=0*/
- -#define leftmargin -50 /* give some room for negative h-coordinate */
- -#define LINELEN 203 /* rightmargin - leftmargin + 1 */
- -
- -#define MOVE TRUE /* if advancing h when outputing a rule */
- -#define STAY FALSE /* if not advancing h when outputing a rule */
- -
- -#define absolute 0 /* for seeking in files */
- -#define relative 1
- -
- -#define FORM 12 /* formfeed */
- -#define SPACE 32 /* space */
- -#define DEL 127 /* delete */
- -
- -#define LASTCHAR 127 /* max dvi character, above are commands */
- -
- -#define IMIN(a, b) (a<b ? a : b)
- -#define IMAX(a, b) (a>b ? a : b)
- -
- -#define get1() num(1)
- -#define get2() num(2)
- -#define get3() num(3)
- -#define get4() num(4)
- -#define sget1() snum(1)
- -#define sget2() snum(2)
- -#define sget3() snum(3)
- -#define sget4() snum(4)
- -
- -char *dvistuff = "(#)@ dvistuff.c 3.1 23/01/89 M.J.E. Mol (c) 1989"
- -
- -/*---------------------------------------------------------------------------*/
- -
- -typedef struct {
- - long hh;
- - long vv;
- - long ww;
- - long xx;
- - long yy;
- - long zz;
- -} stackitem;
- -
- -typedef struct lineptr { /* the lines of text to be output to outfile */
- - long vv; /* vertical position of the line */
- - int charactercount; /* pos of last char on line */
- - struct lineptr *prev; /* preceding line */
- - struct lineptr *next; /* succeeding line */
- - char text[LINELEN+1]; /* leftmargin...rightmargin */
- -} linetype;
- -
- -/*---------------------------------------------------------------------------*/
- -
- -bool pageswitchon; /* true if user-set pages to print */
- -bool sequenceon; /* false if pagesw-nrs refers to TeX-nrs */
- -bool scascii; /* if true make Scand. nat. chars right */
- -bool noffd; /* if true output ^L instead of formfeed */
- -
- -int opcode; /* dvi-opcodes */
- -
- -long h, v; /* coordinates, horizontal and vertical */
- -long w, x, y, z; /* horizontal and vertical amounts */
- -
- -long pagecounter; /* sequence page number counter */
- -long backpointer; /* pointer for offset to previous page */
- -long pagenr; /* TeX page number */
- -int stackmax; /* stacksize required */
- -
- -long maxpagewidth; /* width of widest page in file */
- -long charwidth; /* aprox width of character */
- -
- -linetype * currentline; /* pointer to current line on current page */
- -linetype * firstline; /* pointer to first line on current page */
- -linetype * lastline; /* pointer to last line on current page */
- -int firstcolumn; /* 1st column with something to print */
- -
- -stackitem * stack; /* stack for dvi-pushes */
- -int sptr; /* stack pointer */
- -
- -/*---------------------------------------------------------------------------*/
- -
- -#if defined(MSDOS)
- -void postamble (void);
- -void preamble (void);
- -void walkpages (void);
- -void initpage (void);
- -void dopage (void);
- -void skippage (void);
- -void printpage (void);
- -bool inlist (long);
- -void rule (bool, long, long);
- -void ruleaux (long, long, char);
- -long horizontalmove (long);
- -int skipnops (void);
- -linetype * getline (void);
- -linetype * findline (void);
- -unsigned long num (int);
- -long snum (int);
- -void outchar (char);
- -void putcharacter (long);
- -void setchar (long);
- -#else
- -void postamble ();
- -void preamble ();
- -void walkpages ();
- -void initpage ();
- -void dopage ();
- -void skippage ();
- -void printpage ();
- -bool inlist ();
- -void rule ();
- -void ruleaux ();
- -long horizontalmove ();
- -int skipnops ();
- -linetype * getline ();
- -linetype * findline ();
- -unsigned long num ();
- -long snum ();
- -void outchar ();
- -void putcharacter ();
- -void setchar ();
- -#endif
- -
- -
- -/*---------------------------------------------------------------------------*/
- -/*---------------------------------------------------------------------------*/
- -
- -/*
- - * The main function for processing the dvi file.
- - * Here we assume there are to file pointers: DVIfile and output.
- - * Also we have a list of pages pointed to by 'currentpage',
- - * which is only used (in 'inlist()') when a page list is given.
- - */
- -
- -void dvimain()
- -{
- -
- - postamble(); /* seek and process the postamble */
- - /* note that walkpages *must* immediately follow preamble */
- - preamble(); /* process preamble */
- - walkpages(); /* time to do the actual work! */
- -
- -} /* dvimain */
- -
- -/*---------------------------------------------------------------------------*/
- -
- -void postamble() /* find and process postamble, use random access */
- -{
- - register long size;
- - register int count;
- - struct stat st;
- -
- - fstat (fileno(DVIfile), &st);
- - size = (long) st.st_size; /* get size of file */
- - count = -1;
- - do { /* back file up past signature bytes (223), to id-byte */
- - if (size == 0)
- - errorexit(nopst);
- - size--;
- - fseek(DVIfile, size, absolute);
- - opcode = (int) get1();
- - count++;
- - } while (opcode == TRAILER);
- - if (count < 4) { /* must have 4 trailer bytes */
- - foo = count;
- - errorexit(fwsgn);
- - }
- - if (opcode != VERSIONID)
- - errorexit(badid);
- - fseek(DVIfile, size-4, absolute); /* back up to back-pointer */
- - fseek(DVIfile, sget4(), absolute); /* and to start of postamble */
- - if (get1() != POST)
- - errorexit(nopst);
- - fseek(DVIfile, 20L, relative); /* lastpageoffset, numerator, denominator */
- - /* magnification, maxpageheight */
- - maxpagewidth = sget4();
- - charwidth = maxpagewidth / (ttywidth + espace);
- - stackmax = (int) get2();
- - if ((stack = (stackitem *) malloc(stackmax * sizeof(stackitem))) == NULL)
- - errorexit(stkrq);
- -
- - /* get2() -- totalpages */
- - /* fontdefs */
- -
- -} /* postamble */
- -
- -/*---------------------------------------------------------------------------*/
- -
- -void preamble() /* process preamble, use random access */
- -{
- -
- - fseek(DVIfile, 0L, absolute); /* read the dvifile from the start */
- - if ((opcode = skipnops()) != PRE)
- - errorexit(nopre);
- - opcode = (int) get1(); /* check id in preamble, ignore rest of it */
- - if (opcode != VERSIONID)
- - errorexit(badid);
- - fseek(DVIfile, 12L, relative); /* numerator, denominator, magnification */
- - fseek(DVIfile, get1(), relative); /* skip job identification */
- -
- -} /* preamble */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void walkpages() /* process the pages in the DVI-file */
- -{
- - register bool wantpage;
- -
- - pagecounter = 0L;
- - while ((opcode = skipnops()) != POST) {
- - if (opcode != BOP) /* should be at start of page now */
- - errorexit(nobop);
- - else {
- - pagecounter++;
- - pagenr = sget4(); /* get TeX page number */
- - fseek(DVIfile, 36L, relative); /* skip page header */
- - backpointer = sget4(); /* get previous page offset */
- - if (pageswitchon)
- - if (sequenceon)
- - wantpage = inlist(pagecounter);
- - else
- - wantpage = inlist(pagenr);
- - else
- - wantpage = TRUE;
- -
- - if (wantpage) {
- - initpage();
- - dopage();
- - printpage();
- - }
- - else {
- - skippage();
- - }
- - }
- - }
- -
- -} /* walkpages */
- -
- -/*---------------------------------------------------------------------------*/
- -
- -void initpage()
- -{
- -
- - h = 0L; v = 0L; /* initialize coordinates */
- - x = 0L; w = 0L; y = 0L; z = 0L; /* initialize amounts */
- - sptr = 0; /* initialize stack */
- - currentline = getline(); /* initialize list of lines */
- - currentline->vv = 0L;
- - firstline = currentline;
- - lastline = currentline;
- - firstcolumn = rightmargin;
- - if (pageswitchon) {
- - if ((sequenceon && (pagecounter != firstpage->pag)) ||
- - (!sequenceon && (pagenr != firstpage->pag)))
- - if (noffd)
- - fprintf(output, "^L\n");
- - else
- - putc(FORM, output);
- - }
- - else
- - if (backpointer != -1) /* not FORM at first page */
- - if (noffd)
- - fprintf(output, "^L\n");
- - else
- - putc(FORM, output);
- -
- -} /* initpage */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void dopage()
- -{
- -
- - while ((opcode = (int) get1()) != EOP) { /* process page until eop */
- - if (opcode > POST_POST)
- - errorexit(illop);
- - else if (opcode <= LASTCHAR)
- - outchar((char) opcode);
- - else
- - switch (opcode) {
- - case SET1 : setchar(get1()); break;
- - case SET2 : setchar(get2()); break;
- - case SET3 : setchar(get3()); break;
- - case SET4 : setchar(get4()); break;
- - case SET_RULE : rule(MOVE, sget4(), sget4()); break;
- - case PUT1 : putcharacter(get1()); break;
- - case PUT2 : putcharacter(get2()); break;
- - case PUT3 : putcharacter(get3()); break;
- - case PUT4 : putcharacter(get4()); break;
- - case PUT_RULE : rule(STAY, sget4(), sget4()); break;
- - case NOP : break; /* no-op */
- - case BOP : errorexit(bdbop); break;
- -/* case EOP : break; strange place to have EOP */
- - case PUSH : if (sptr >= stackmax) /* push */
- - errorexit(stkof);
- - stack[sptr].hh = h;
- - stack[sptr].vv = v;
- - stack[sptr].ww = w;
- - stack[sptr].xx = x;
- - stack[sptr].yy = y;
- - stack[sptr].zz = z;
- - sptr++;
- - break;
- - case POP : if (sptr == 0) /* pop */
- - errorexit(stkuf);
- - sptr--;
- - h = stack[sptr].hh;
- - v = stack[sptr].vv;
- - w = stack[sptr].ww;
- - x = stack[sptr].xx;
- - y = stack[sptr].yy;
- - z = stack[sptr].zz;
- - break;
- - case RIGHT1 : (void) horizontalmove(sget1()); break;
- - case RIGHT2 : (void) horizontalmove(sget2()); break;
- - case RIGHT3 : (void) horizontalmove(sget3()); break;
- - case RIGHT4 : (void) horizontalmove(sget4()); break;
- - case W0 : h += w; break;
- - case W1 : w = horizontalmove(sget1()); break;
- - case W2 : w = horizontalmove(sget2()); break;
- - case W3 : w = horizontalmove(sget3()); break;
- - case W4 : w = horizontalmove(sget4()); break;
- - case X0 : h += x; break;
- - case X1 : x = horizontalmove(sget1()); break;
- - case X2 : x = horizontalmove(sget2()); break;
- - case X3 : x = horizontalmove(sget3()); break;
- - case X4 : x = horizontalmove(sget4()); break;
- - case DOWN1 : v += sget1(); break;
- - case DOWN2 : v += sget2(); break;
- - case DOWN3 : v += sget3(); break;
- - case DOWN4 : v += sget4(); break;
- - case Y0 : v += y; break;
- - case Y1 : y = sget1(); v += y; break;
- - case Y2 : y = sget2(); v += y; break;
- - case Y3 : y = sget3(); v += y; break;
- - case Y4 : y = sget4(); v += y; break;
- - case Z0 : v += z; break;
- - case Z1 : z = sget1(); v += z; break;
- - case Z2 : z = sget2(); v += z; break;
- - case Z3 : z = sget3(); v += z; break;
- - case Z4 : z = sget4(); v += z; break;
- - case FNT1 :
- - case FNT2 :
- - case FNT3 : /* ignore font changes */
- - case FNT4 : fseek(DVIfile, (long) opcode-FNT1+1, relative);
- - break;
- - case XXX1 : fseek(DVIfile, get1(), relative); break;
- - case XXX2 : fseek(DVIfile, get2(), relative); break;
- - case XXX3 : fseek(DVIfile, get3(), relative); break;
- - case XXX4 : fseek(DVIfile, get4(), relative); break;
- - case FNT_DEF1 :
- - case FNT_DEF2 :
- - case FNT_DEF3 : /* ignore font definitions */
- - case FNT_DEF4 : fseek(DVIfile, (long) opcode-FNT_DEF1+1+12,
- - relative);
- - fseek(DVIfile, get1() + get1(), relative);
- - break;
- - case PRE : errorexit(bdpre); break;
- - case POST : errorexit(bdpst); break;
- - case POST_POST: errorexit(bdpp); break;
- - }
- - }
- -
- -} /* dopage */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void skippage() /* skip past one page */
- -{
- - register int opcode;
- -
- - while ((opcode = (int) get1()) != EOP) {
- - if (opcode > POST_POST)
- - errorexit(illop);
- - else
- - switch (opcode) {
- - case SET1 :
- - case PUT1 :
- - case RIGHT1 :
- - case W1 :
- - case X1 :
- - case DOWN1 :
- - case Y1 :
- - case Z1 :
- - case FNT1 : fseek(DVIfile, 1L, relative); break;
- - case SET2 :
- - case PUT2 :
- - case RIGHT2 :
- - case W2 :
- - case X2 :
- - case DOWN2 :
- - case Y2 :
- - case Z2 :
- - case FNT2 : fseek(DVIfile, 2L, relative); break;
- - case SET3 :
- - case PUT3 :
- - case RIGHT3 :
- - case W3 :
- - case X3 :
- - case DOWN3 :
- - case Y3 :
- - case Z3 :
- - case FNT3 : fseek(DVIfile, 3L, relative); break;
- - case SET4 :
- - case PUT4 :
- - case RIGHT4 :
- - case W4 :
- - case X4 :
- - case DOWN4 :
- - case Y4 :
- - case Z4 :
- - case FNT4 : fseek(DVIfile, 4L, relative); break;
- - case SET_RULE :
- - case PUT_RULE : fseek(DVIfile, 8L, relative); break;
- - case BOP : errorexit(bdbop); break;
- - case XXX1 : fseek(DVIfile, get1(), relative); break;
- - case XXX2 : fseek(DVIfile, get2(), relative); break;
- - case XXX3 : fseek(DVIfile, get3(), relative); break;
- - case XXX4 : fseek(DVIfile, get4(), relative); break;
- - case FNT_DEF1 :
- - case FNT_DEF2 :
- - case FNT_DEF3 :
- - case FNT_DEF4 : fseek(DVIfile, (long) opcode-FNT_DEF1+1+12,
- - relative);
- - fseek(DVIfile, get1()+get1(), relative);
- - break;
- - case PRE : errorexit(bdpre); break;
- - case POST : errorexit(bdpst); break;
- - case POST_POST: errorexit(bdpp); break;
- - }
- - }
- -
- -} /* skippage */
- -
- -/*---------------------------------------------------------------------------*/
- -
- -void printpage() /* 'end of page', writes lines of page to output file */
- -{
- - register int i, j;
- - register char ch;
- -
- - if (sptr != 0)
- - fprintf(stderr, "dvi2tty: warning - stack not empty at eop.\n");
- - for (currentline = firstline; currentline != nil;
- - currentline = currentline->next) {
- - if (currentline != firstline) {
- - foo = ((currentline->vv - currentline->prev->vv)/VERTICALEPSILON)-1;
- - if (foo > 3)
- - foo = 3; /* linespacings not too large */
- - for (i = 1; i <= (int) foo; i++)
- - putc('\n', output);
- - }
- - if (currentline->charactercount >= leftmargin) {
- - foo = ttywidth - 2;
- - for (i = firstcolumn, j = 1; i <= currentline->charactercount;
- - i++, j++) {
- - ch = currentline->text[i - leftmargin];
- - if (ch >= SPACE)
- - putc(ch, output);
- - if ((j > (int) foo) && (currentline->charactercount > i+1)) {
- - fprintf(output, "*\n"); /* if line to large */
- - fprintf(output, " *"); /* mark output */
- - j = 2;
- - }
- - }
- - }
- - putc('\n', output);
- - }
- -
- - currentline = firstline;
- - while (currentline->next != nil) {
- - currentline = currentline->next;
- - free(currentline->prev);
- - }
- - free(currentline); /* free last line */
- - currentline = nil;
- -
- -} /* printpage */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -bool inlist(pagenr) /* ret true if in list of pages */
- -register long pagenr;
- -{
- -
- - while ((currentpage->pag < 0) && (currentpage->pag != pagenr) &&
- - !currentpage->all && (currentpage->nxt != nil))
- - currentpage = currentpage->nxt;
- - if ((currentpage->all && (pagenr < currentpage->pag)) ||
- - (currentpage->pag == pagenr))
- - return TRUE;
- - else if (pagenr > 0) {
- - while ((currentpage->pag < pagenr) && (currentpage->nxt != nil))
- - currentpage = currentpage->nxt;
- - if (currentpage->pag == pagenr)
- - return TRUE;
- - }
- - return FALSE;
- -
- -} /* inlist */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void rule(moving, rulewt, ruleht)
- -register bool moving;
- -register long rulewt, ruleht;
- -{ /* output a rule (vertical or horizontal), increment h if moving is true */
- -
- - register char ch; /* character to set rule with */
- - register long saveh, savev;
- - /* rule -- starts up the recursive routine */
- - if (!moving)
- - saveh = h;
- - if ((ruleht <= 0) || (rulewt <= 0))
- - h += rulewt;
- - else {
- - savev = v;
- - if ((ruleht / rulewt) > 0)
- - ch = '|';
- - else if (ruleht > (VERTICALEPSILON / 2))
- - ch = '=';
- - else
- - ch = '_';
- - ruleaux(rulewt, ruleht, ch);
- - v = savev;
- - }
- - if (!moving)
- - h = saveh;
- -
- -} /* rule */
- -
- -
- -
- -void ruleaux(rulewt, ruleht, ch) /* recursive that does the job */
- -register long rulewt, ruleht;
- -register char ch;
- -{
- - register long wt, lmh, rmh;
- -
- - wt = rulewt;
- - lmh = h; /* save left margin */
- - if (h < 0) { /* let rules that start at negative h */
- - wt -= h; /* start at coordinate 0, but let it */
- - h = 0; /* have the right length */
- - }
- - while (wt > 0) { /* output the part of the rule that */
- - rmh = h; /* goes on this line */
- - outchar(ch);
- - wt -= (h-rmh); /* decrease the width left on line */
- - }
- - ruleht -= VERTICALEPSILON; /* decrease the height */
- - if (ruleht > VERTICALEPSILON) { /* still more vertical? */
- - rmh = h; /* save current h (right margin) */
- - h = lmh; /* restore left margin */
- - v -= (VERTICALEPSILON + VERTICALEPSILON / 10);
- - ruleaux(rulewt, ruleht, ch);
- - h = rmh; /* restore right margin */
- - }
- -
- -} /* ruleaux */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -long horizontalmove(amount)
- -register long amount;
- -{
- -
- -#if defined(MSDOS)
- - if (labs(amount) > charwidth / 4L) {
- -#else
- - if (abs(amount) > charwidth / 4L) {
- -#endif
- - foo = 3*charwidth / 4;
- - if (amount > 0)
- - amount = ((amount+foo) / charwidth) * charwidth;
- - else
- - amount = ((amount-foo) / charwidth) * charwidth;
- - h += amount;
- - return amount;
- - }
- - else
- - return 0;
- -
- -} /* horizontalmove */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -int skipnops() /* skips by no-op commands */
- -{
- - register int opcode;
- -
- - while ((opcode = (int) num(1)) == NOP);
- - return opcode;
- -
- -} /* skipnops */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -linetype *getline() /* returns an initialized line-object */
- -{
- - register int i;
- - register linetype *temp;
- -
- - if ((temp = (linetype *) malloc(sizeof(linetype))) == NULL)
- - errorexit(lnerq);
- - temp->charactercount = leftmargin - 1;
- - temp->prev = nil;
- - temp->next = nil;
- - for (i = 0; i < LINELEN; i++)
- - temp->text[i] = ' ';
- - temp->text[i] = '\0';
- - return temp;
- -
- -} /* getline */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -linetype *findline() /* find best fit line were text should go */
- -{ /* and generate new line if needed */
- - register linetype *temp;
- - register long topd, botd;
- -
- - if (v <= firstline->vv) { /* above first line */
- - if (firstline->vv - v > VERTICALEPSILON) {
- - temp = getline();
- - temp->next = firstline;
- - firstline->prev = temp;
- - temp->vv = v;
- - firstline = temp;
- - }
- - return firstline;
- - }
- -
- - if (v >= lastline->vv) { /* below last line */
- - if (v - lastline->vv > VERTICALEPSILON) {
- - temp = getline();
- - temp->prev = lastline;
- - lastline->next = temp;
- - temp->vv = v;
- - lastline = temp;
- - }
- - return lastline;
- - }
- -
- - temp = lastline; /* in between two lines */
- - while ((temp->vv > v) && (temp != firstline))
- - temp = temp->prev;
- -
- - /* temp->vv < v < temp->next->vv --- temp is above, temp->next is below */
- - topd = v - temp->vv;
- - botd = temp->next->vv - v;
- - if ((topd < VERTICALEPSILON) || (botd < VERTICALEPSILON))
- - if (topd < botd) /* take best fit */
- - return temp;
- - else
- - return temp->next;
- -
- - /* no line fits suitable, generate a new one */
- - currentline = getline();
- - currentline->next = temp->next;
- - currentline->prev = temp;
- - temp->next->prev = currentline;
- - temp->next = currentline;
- - currentline->vv = v;
- - return currentline;
- -
- -} /* findline */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -unsigned long num(size)
- -register int size;
- -{
- - register int i;
- - register long x = 0;
- -
- - for (i = 0; i < size; i++)
- - x = (x << 8) + (unsigned) getc(DVIfile);
- - return x;
- -
- -} /* num */
- -
- -
- -long snum(size)
- -register int size;
- -{
- - register int i;
- - register long x = 0;
- -
- - x = getc(DVIfile);
- - if (x & 0x80)
- - x -= 0x100;
- - for (i = 1; i < size; i++)
- - x = (x << 8) + (unsigned) getc(DVIfile);
- - return x;
- -
- -} /* snum */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void outchar(ch) /* output ch to appropriate line */
- -register char ch;
- -{
- - register int i, j;
- -
- -/* fprintf(stderr, "hor: %ld, ver: %ld\n", h, v); */
- -#if defined(MSDOS)
- - if (labs(v - currentline->vv) > VERTICALEPSILON / 2L)
- -#else
- - if (abs(v - currentline->vv) > VERTICALEPSILON / 2L)
- -#endif
- - currentline = findline();
- - switch (ch) {
- - case 11 : outchar('f'); ch = 'f'; break; /* ligature */
- - case 12 : outchar('f'); ch = 'i'; break; /* ligature */
- - case 13 : outchar('f'); ch = 'l'; break; /* ligature */
- - case 14 : outchar('f'); outchar('f');
- - ch = 'i'; break; /* ligature */
- - case 15 : outchar('f'); outchar('f');
- - ch = 'l'; break; /* ligature */
- - case 16 : ch = 'i'; break;
- - case 17 : ch = 'j'; break;
- - case 25 : outchar('s'); ch = 's'; break; /* German double s */
- - case 26 : outchar('a'); ch = 'e'; break; /* Dane/Norw ae */
- - case 27 : outchar('o'); ch = 'e'; break; /* Dane/Norw oe */
- - case 28 : if (scascii)
- - ch = '|'; /* Dane/Norw /o */
- - else
- - ch = 'o';
- - break;
- - case 29 : outchar('A'); ch = 'E'; break; /* Dane/Norw AE */
- - case 30 : outchar('O'); ch = 'E'; break; /* Dane/Norw OE */
- - case 31 : if (scascii)
- - ch = '\\'; /* Dane/Norw /O */
- - else
- - ch = 'O';
- - break;
- -#if 0
- - case 92 : ch = '"'; break; /* beginning qoute */
- - case 123 : ch = '-'; break;
- - case 124 : ch = '_'; break;
- - case 125 : ch = '"'; break;
- - case 126 : ch = '"'; break;
- -#endif
- - }
- -#if 0
- - j = (int) (((double) h / (double) maxpagewidth) * (ttywidth-1)) + 1;
- -#else
- - j = (int) (h / charwidth);
- -#endif
- - if (j > rightmargin)
- - j = rightmargin;
- - else if (j < leftmargin)
- - j = leftmargin;
- - foo = leftmargin - 1;
- - /*-------------------------------------------------------------*/
- - /* The following is very specialized code, it handles national */
- - /* Swedish characters. They are respectively: a and o with two */
- - /* dots ("a & "o) and a with a circle (Oa). In Swedish "ASCII" */
- - /* these characters replace }{|][ and \. TeX outputs these by */
- - /* first issuing the dots or circle and then backspace and set */
- - /* the a or o. When dvitty finds an a or o it searches in the */
- - /* near vicinity for the character codes that represent circle */
- - /* or dots and if one is found the corresponding national char */
- - /* replaces the special character codes. */
- - /*-------------------------------------------------------------*/
- - if (scascii) {
- - if ((ch == 'a') || (ch == 'A') || (ch == 'o') || (ch == 'O')) {
- - for (i = IMAX(leftmargin, j-2);
- - i <= IMIN(rightmargin, j+2);
- - i++)
- - if ((currentline->text[i - leftmargin] == 127) ||
- - (currentline->text[i - leftmargin] == 23))
- - foo = i;
- - if (foo >= leftmargin) {
- - j = (int) foo;
- - switch (currentline->text[j - leftmargin]) {
- - case 127 : if (ch == 'a')
- - ch = '{';
- - else if (ch == 'A') /* dots ... */
- - ch = '[';
- - else if (ch == 'o')
- - ch = '|';
- - else if (ch == 'O')
- - ch = '\\';
- - break;
- - case 23 : if (ch == 'a')
- - ch = '}';
- - else if (ch == 'A') /* circle */
- - ch = ']';
- - break;
- - }
- - }
- - }
- - }
- - /*----------------- end of 'Scandinavian code' ----------------*/
- - if (foo == leftmargin-1)
- - while ((currentline->text[j - leftmargin] != SPACE)
- - && (j < rightmargin)) {
- - j++;
- - h += charwidth;
- - }
- - if ( ((ch >= SPACE) && (ch != DEL)) ||
- - (scascii && (ch == 23)) ) {
- - if (j < rightmargin)
- - currentline->text[j - leftmargin] = ch;
- - else
- - currentline->text[rightmargin - leftmargin] = '@';
- - if (j > currentline->charactercount)
- - currentline->charactercount = j;
- - if (j < firstcolumn)
- - firstcolumn = j;
- - h += charwidth;
- - }
- -
- -} /* outchar */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void putcharacter(charnr) /* output character, don't change h */
- -register long charnr;
- -{
- - register long saveh;
- -
- - saveh = h;
- - if ((charnr >= 0) && (charnr <= LASTCHAR))
- - outchar((char) charnr);
- - else
- - setchar(charnr);
- - h = saveh;
- -
- -} /* putcharacter */
- -
- -/*----------------------------------------------------------------------------*/
- -
- -void setchar(charnr)
- -long charnr;
- -{ /* should print characters with character code>127 from current font */
- - /* note that the parameter is a dummy, since ascii-chars are<=127 */
- -
- - outchar('#');
- -
- -} /* setchar */
- -
- _E_O_F_
- if test 31593 -ne `wc -c < dvistuff.c `; then
- echo shar: "'dvistuff.c'" unpacked with wrong size!
- fi
- # end of shell archive
- exit 0
- --
- #########################################
- # Marcel J.E. Mol # They hate you if your're clever
- # Delft, University of Technology # And they despise the fool
- # The Netherlands # Till you're so fucking crazy
- # UUCP: marcel@duteca.UUCP # You can't follow the rules.
- # duteca!marcel #
- ######################################### - Lennon
-